<template>
    <div class="layerRtb layerRtb-threecolumn">
        <three-title :title="{name:'管理'}"></three-title>
        <div v-if="StatusCode==0" class="layerRtb-scroll thinScroll" v-scrollHeight="137">

            <div class="analyItem " active-class="anItemBor-active" v-for="(item,index) in body" :key="index">
                <p class="analyItemTit tx-center">订单{{Number(index)+Number(1)}}</p>
                <div class="analyItemCon">
                    <p class="col-md-4 ">
                        <span class="cLightGray pr8">订单名</span>
                        <span>{{item.orderName}}</span>
                    </p>
                    <p class="col-md-4 ">
                        <span class="cLightGray pr8">开始时间</span>
                        <span>{{item.createDate}}</span>
                    </p>
                    <p class="col-md-4 ">
                        <span class="cLightGray pr8">截止时间</span>
                        <span>{{item.deadLine}}</span>
                    </p>
                    <p class="col-md-4 ">
                        <span class="cLightGray pr8">订单阶段</span>
                        <span>{{item.orderPhase}}</span>
                    </p>
                    <p class="col-md-4 ">
                        <span class="cLightGray pr8">订单内容</span>
                        <span>{{item.orderContent}}</span>
                    </p>

                    <p class="col-md-4 ">
                        <span class="cLightGray pr8">验收评语</span>
                        <span>{{item.resultContent}}</span>
                    </p>

                    <p class="col-md-4 ">
                        <span class="cLightGray pr8">实收金额</span>
                        <span>{{item.realIncome}}</span>
                    </p>
                    <p class="col-md-4 ">
                        <span class="cLightGray pr8">实收积分</span>
                        <span>{{item.realIncomeScore}}</span>
                    </p>
                    <span class="circlemark" :class="item.result | evaluateColor">{{item.result}}</span>
                </div>
            </div>

        </div>
        <div v-else class="layerRtb-scroll thinScroll" v-scrollHeight="137">

            <div class="analyItem " active-class="anItemBor-active">
                <p class="analyItemTit tx-center">暂无数据</p>
                <div class="analyItemCon">

                </div>
            </div>

        </div>
        <div class="layerRtb-footer">
            <router-link tag="div" :to="routerPath('hander')" class="analyItem " active-class="anItemBor-active">
                <p class="analyItemTit tx-center">综合</p>
                <div class="analyItemCon">
                    <p class="col-md-3 ">
                        <span class="cLightGray pr8">订单</span>
                        <span class="cGreen">{{countSum}}</span>
                    </p>
                    <p class="col-md-3 ">
                        <span class="cLightGray pr8">应完</span>
                        <span class="cGreen">{{countSum}}</span>
                    </p>
                    <p class="col-md-3 ">
                        <span class="cLightGray pr8">未完</span>
                        <span class="cGreen">{{countSum-completedNum}}</span>
                    </p>
                    <p class="col-md-3 ">
                        <span class="cLightGray pr8">完成比</span>
                        <span class="cGreen">{{wanchengbi}}%</span>
                    </p>
                </div>
            </router-link>
        </div>
    </div>
</template>
<script>
import {
    mapGetters
} from 'vuex'
import { getStayStayManagementDetail, projectManagerOrderAnalysis, getStayStayManagementEvaluation, getUserManageMonthEvaluation } from '../../Resources/Api'
export default {
    data () {
        return {
            achieveMentList: [], // 绩效集合
            completionList: {},
            // 项目总数
            projectSum: 0,
            // 竣工金额
            completion_money: 0,
            // 竣工提成
            comprehensive_completion: 0,
            // 罚款金额
            fine_money: 0,
            // 罚款提成
            comprehensive_fine: 0,
            // 洽商金额
            negotiate_profit: 0,
            // 洽商提成
            comprehensive_negotiate: 0,
            tradeDetail: {},
            stayCompleteState: 5,
            stayCarryState: 5,
            stayDiscussState: 5,
            StatusCode: 500,
            wanchengbi: 0, // 完成比
            completedNum: 0, // 完成数量
            countSum: 0, // 总数
            body: []
        }
    },
    created () {
        this.stayCompleteDataFn()
        this.GetUserTradeDetailByUserCardFn()
        this.projectManagerOrderAnalysisFn()
    },
    methods: {
    // 路由跳转路径拼接
        routerPath (path) {
            return this.$route.matched[1].path + '/' + path
        },
        // 直接进行路由跳转路径
        routerPush (path) {
            this.$router.push(this.$route.matched[1].path + '/' + path)
        },
        projectManagerOrderAnalysisFn () {
            let nowDate = new Date()
            let date = {
                year: nowDate.getFullYear(),
                month: nowDate.getMonth() + 1,
                date: nowDate.getDate()
            }
            let systemDate = date.year + '-' + 0 + date.month
            // + '-' + 0 + date.date
            projectManagerOrderAnalysis({
                cardNum: this.leftInfo.cardNo,
                monthAndYear: systemDate
            }).then(results => {
                this.StatusCode = results.data.StatusCode
                if (this.StatusCode === 0) {
                    this.body = results.data.Body
                    this.completedNum = results.data.completedNum
                    this.countSum = this.body.length
                    this.wanchengbi = (this.completedNum / this.countSum) * 100
                } else {
                    this.completedNum = 0
                    this.countSum = 0
                    this.wanchengbi = 0
                }
            }).catch(error => {
                console.log(error)
            })
        },

        // 查询本月留竣工提成数据
        stayCompleteDataFn () {
            getStayStayManagementDetail({
                user_card_no: this.leftInfo.cardNo
            }).then(results => {
                this.completionList = results.data.Body
                this.completion_money = 0
                this.projectSum = 0
                this.completion_money = 0
                this.comprehensive_completion = 0
                this.fine_money = 0
                this.comprehensive_fine = 0
                this.negotiate_profit = 0
                this.comprehensive_negotiate = 0
                for (var i = 0; i < this.completionList.length; i++) {
                    this.projectSum++
                    this.completion_money += this.completionList[i].completion_money
                    this.comprehensive_completion += this.completionList[i].comprehensive_completion
                    this.fine_money += this.completionList[i].fine_money
                    this.negotiate_profit += this.completionList[i].negotiate_profit
                    this.comprehensive_fine += this.completionList[i].comprehensive_fine
                    this.comprehensive_negotiate += this.completionList[i].comprehensive_negotiate
                }
            }).catch(error => {
                console.log(error)
            })
        },
        GetUserTradeDetailByUserCardFn () {
            getStayStayManagementEvaluation({
                user_card_no: this.leftInfo.cardNo
            }).then(results => {
                this.tradeDetail = results.data.Body
                if (this.tradeDetail != null) {
                    this.stayCompleteState = this.tradeDetail.stayCompleteState
                    this.stayCarryState = this.tradeDetail.stayCarryState
                    this.stayDiscussState = this.tradeDetail.stayDiscussState
                }
            }).catch(error => {
                console.log(error)
            })
        },
        getUserManageMonthEvaluation () {
            let parm = {
                user_card_no: this.leftInfo.cardNo
            }
            // 获取绩效接口
            getUserManageMonthEvaluation(parm).then((result) => {
                if (result.data.StatusCode === 0) {
                    this.achieveMentList = result.data.Body.allOnJobGCJL
                }
            }).catch((error) => {
                console.log(error)
            })
        }
    },
    filters: {
        evaluate: function (str) {
            switch (Number(str)) {
            case 1:
                return '优'
            case 2:
                return '良'
            case 3:
                return '中'
            case 4:
                return '差'
            case 0:
                return '待'
            }
        },
        resultColor: function (str) {
            switch (Number(str)) {
            case 0:
                return 'cPurple'
            case 1:
                return 'cGreen'
            case 2:
                return 'cLightGreen'
            case 3:
                return 'cYellow'
            case 4:
                return 'cRed'
            }
        },
        evaluateColor: function (str) {
            switch (str) {
            case '0':
                return 'circlemark-purple'
            case '优':
                return 'circlemark-green'
            case '良':
                return 'circlemark-lightGreen'
            case '中':
                return 'circlemark-yellow'
            case '差':
                return 'circlemark-lightRed'
            }
        }
    },
    computed: {
        ...mapGetters(['leftInfo'])
    },
    watch: {
        leftInfo () {
            this.stayCompleteDataFn()
            this.GetUserTradeDetailByUserCardFn()
            this.getUserManageMonthEvaluation()
            this.projectManagerOrderAnalysisFn()
        }
    }
}
</script>
